package ai.jobs;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.e4.core.services.events.IEventBroker;

import ai.service.AIService;

public class AIJob extends Job {
	private AIService aiService;
	private String questionContext;
	private IEventBroker eventBroker;

	public AIJob(String name, String questionContext, AIService aiService, IEventBroker eventBroker) {
		super(name);
		this.aiService = aiService;
		this.questionContext = questionContext;
		this.eventBroker = eventBroker;
	}

	@Override
	protected IStatus run(IProgressMonitor monitor) {
		eventBroker.post("ai/waiting", null);
		String answer = aiService.getAnswers(questionContext);
		eventBroker.post("ai/addAnswerToText", answer);
		return Status.OK_STATUS;
	}

}
